package com.itheima.scheduled;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Slf4j
public class ValidateCodeScheduled {

    @Autowired
    private RedisTemplate redisTemplate;


    @Transactional
    @Scheduled(cron = "0 0/5 * * * ? ")   //每5分钟执行一次
    public void execute() {
        log.info("定时删除验证码");
        //删除redis中的验证码
        redisTemplate.delete("ValidateCode");
        redisTemplate.delete("MesValidateCode");


    }


}
